/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package my.javax.microedition.contactless.ndef;

import com.ericsson.nfc.jsr257.impl.NDEFMessageImpl;

/**
 *
 * @author emarkki
 */
public class NDEFRecord {
    private NDEFRecordType recordType;
    private byte[] id;
    private byte[] payload;

    public NDEFRecord(byte[] data, int offset) {
        NDEFMessage msg = new NDEFMessage(data, offset);
        this.recordType = msg.getRecord(0).getRecordType();
        this.id = msg.getRecord(0).getId();
        this.payload = msg.getRecord(0).getPayload();
    }

    public NDEFRecord(NDEFRecordType recordType, byte[] id, byte[] payload) {
        this.recordType = recordType;
        this.id = id;
        this.payload = payload;
    }

    public byte[] getId() {
        return id;
    }

    public NDEFMessage getNestedNDEFMessage(int offset) {
        return new NDEFMessage(payload, offset);
    }

    public byte[] getPayload() {
        return payload;
    }

    public int getPayloadLength() {
        return payload.length;
    }

    public byte[] toByteArray() {
        return NDEFMessageImpl.toRecordByteArray(this);
    }

    public NDEFRecordType getRecordType() {
        return recordType;
    }
    
}
